//
//  SWHomeViewController.m
//  ShiWu
//
//  Created by  on 2022/7/27.
//

#import "SWHomeViewController.h"
#import "SWHomeCell.h"
#import "SWSettingViewController.h"
#import "SWDetailViewController.h"

@interface SWHomeViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (nonatomic, strong) NSArray *imgs;
@end

@implementation SWHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.imgs = @[@"底图",@"启动图"];
    [self.collectionView registerNib:[SWHomeCell nib] forCellWithReuseIdentifier:[SWHomeCell ID]];
    if (@available(iOS 11, *))
    {
        self.collectionView.contentInsetAdjustmentBehavior  = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}
- (IBAction)actionForSetting:(UIButton *)sender {
    SWSettingViewController *vc = [[SWSettingViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
///识别当前图片
- (IBAction)actionForLook:(UIButton *)sender {
    int index = self.collectionView.contentOffset.y / self.collectionView.frame.size.height;
    UIImage *img = [UIImage imageNamed:self.imgs[index]];
    [SWTool swIMG:img type:ShiWuTypePlanet success:^(NSDictionary * _Nonnull dict) {
        if (dict != nil) {
            SWDetailViewController *vc = [[SWDetailViewController alloc] init];
            vc.IMG = img;
            vc.dict = dict;
            [self.navigationController pushViewController:vc animated:true];
        }
    }];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return  self.imgs.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    SWHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:[SWHomeCell ID] forIndexPath:indexPath];
    cell.img.image = [UIImage imageNamed:self.imgs[indexPath.item]];
    return  cell;
}
#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *img = [UIImage imageNamed:self.imgs[indexPath.row]];
}
#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return  CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - TabBarHight);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsZero;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
@end
